package chapter03.test;

public class Student {
    //no表示学号；
    //name表示姓名；
    //sex表示性别；
    //age表示年龄；
    //java：表示Java课程成绩。

    private String no;
    private String name;
    private String sex;
    private int age;
    private double java;

    public Student(String no, String name, String sex, int age, double java) {
        this.no = no;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.java = java;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getJava() {
        return java;
    }

    public void setJava(double java) {
        this.java = java;
    }

    public static void main(String[] args) {
        Student stu1 = new Student("01", "学生1", "男", 18, 80);
        Student stu2 = new Student("02", "学生2", "男", 18, 90);
        Student stu3 = new Student("03", "学生3", "男", 18, 60);
        Student stu4 = new Student("04", "学生4", "男", 18, 70);
        Student stu5 = new Student("05", "学生5", "男", 18, 100);

        double[] stuJavaArray = {stu1.getJava(), stu2.getJava(), stu3.getJava(), stu4.getJava(), stu5.getJava()};

        // 平均值
        System.out.println("平均值：" + computeMean(stuJavaArray));

        // 最大值
        System.out.println("最大值：" + computeMax(stuJavaArray));

        // 最小值
        System.out.println("最小值：" + computeMin(stuJavaArray));

    }

    private static double computeMin(double[] stuJavaArray) {
        double min = stuJavaArray[0];
        for (int i = 0; i < stuJavaArray.length; i++) {
            double java = stuJavaArray[i];
            if (java < min) {
                min = java;
            }
        }

        return min;
    }

    private static double computeMax(double[] stuJavaArray) {
        double max = stuJavaArray[0];
        for (double java : stuJavaArray) {
            if (java > max) {
                max = java;
            }
        }
        return max;
    }

    private static double computeMean(double[] stuJavaArray) {
        double sum = 0;
        for (double java : stuJavaArray) {
            sum += java;
        }
        double mean = sum / stuJavaArray.length;
        return mean;
    }

}
